import { createRouter, createWebHashHistory } from 'vue-router'

// 路由规则
const routes = [
  // 一级路由布局容器
  {
    path: '/',
    component: ()=>import("../views/Layout.vue"),
    children: [{ //详情页
        path:"home",
        name:"home",
         component: ()=>import("../views/Home/index.vue"),
        },
        {//详情页:pid 进入详情页的必传参数pid
        path:"detail/:pid",
        name:"detail",
         component: ()=>import("../views/Detail/index.vue"),
        }
    ]
  },
  { path: '/login', component: ()=>import("../views/Login/index.vue") },

]

const router = createRouter({
  // 使用hash的路由模式
  history: createWebHashHistory(),
  routes,
  // 每次切换路由的时候滚动到页面顶部
  scrollBehavior () {
    // vue2.0  x  y  控制
    // vue3.0  left  top 控制
    return { left: 0, top: 0 }
  }
})


export default router
